<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/api.css">
    <style>
        body,
        html {
            background-color: #fff;
        }

        #back img {
            width: 0.8rem;
            height: 0.8rem;
            margin-left: 0.8rem;
        }

        .hd {
            height: 2rem;
            background-color: transparent;
        }


        .logo {
            width: 8rem;
            height: 8rem;
            margin: 3rem 0 3rem 5.5rem;
        }

        .user_phone,
        .user_psw {
            padding: 0 2rem;
            position: relative;
        }

        .user_psw .auth_code {
            position: absolute;
            right: 2rem;
            font-size: 0.6rem;
            top: 1.1rem;
        }

        .user_phone img,
        .user_psw img {
            width: 1rem;
            height: 1.4rem;
            position: absolute;
            left: 2.5rem;
            top: 0.75rem;
        }

        input {
            width: 85%;
            padding-left: 15%;
            height: 3rem;
            line-height: 3rem;
            border-bottom: 1px solid #eee !important;
            outline: none;
        }

        .register_forget {
            width: 100%;
            height: 1rem;
            font-size: 0.6rem;
            margin: 0.5rem 0;
        }

        .register_forget .register {
            float: left;
            margin-left: 2rem;
            color: #838383;
        }

        .register_forget .forget {
            float: right;
            margin-right: 2rem;
        }

        .login_btn {
            padding: 0 2rem;
            margin-top: 2rem;
        }

        .login_btn div {
            width: 100%;
            height: 2rem;
            background-color: #2780e8;
            text-align: center;
            line-height: 2rem;
            border-radius: 0.2rem;
            color: #fff;
            font-size: 0.7rem;
        }

        .line {
            padding: 0 2rem;
            margin-top: 4rem;
            color: #838383;
            font-size: 0.6rem;
            position: relative;
        }

        .line div {
            width: 35%;
            height: 1px;
            background-color: #838383;
        }

        .line div:first-child {
            float: left;
        }

        .line div:last-child {
            float: right;
        }

        .line p {
            position: absolute;
            top: -0.5rem;
            left: 42%;
        }

        .wx_login {
            width: 100%;
            height: 2rem;
            text-align: center;
            padding: 2rem 0;
        }

        .wx_login img {
            width: 2rem;
            height: 2rem;
        }

        .order {
            position: relative;
            margin-top: 6rem;
            font-size: .6rem;
            line-height: .8rem;
            text-align: center;
        }

        .order_icon {
            position: absolute;
            width: .7rem;
            height: .7rem;
            margin-left: -1rem;
        }

        .order span {
            margin: 0 .2rem;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div>
            <img class="logo" src="../image/logo.png" alt="">
        </div>

        <div class="user_phone">
            <img src="../image/phone_icon.png" alt="">
            <input type="tel" maxlength="11" v-model="phoneNum" placeholder="请输入您的手机号">
        </div>
        <div class="user_psw">
            <img src="../image/auth_code_icon.png" alt="">
            <input type="text" v-model="code" placeholder="请输入验证码">
            <div class="auth_code" @click="getCode()">{{getAuthCode}}</div>
        </div>

        <div class="register_forget">
            <p class="register">提示：未注册的用户登录即注册</p>
        </div>

        <div class="login_btn" @click="login()">
            <div>登 录</div>
        </div>
        <p class="order" @click="order = !order">
            <img class="order_icon" :src="order ? '../image/icon_radio_checked.png' : '../image/icon_radio.png' "
                alt="">
            您已经阅读并同意<span class="openwin" data-win="fuwu_tiaokuan_win" style="color: #2780e8;">服务条款</span>和<span
                class="openwin" data-win="yinsi_win" style="color: #2780e8;">隐私政策</span></p>

        <!-- <div class="line">
            <div></div>
            <p>第三方登录</p>
            <div></div>
        </div>

        <div class="wx_login" onclick="wxLogin()">
            <img src="../image/wx_icon.png" alt="">
        </div> -->
    </div>
</body>

</html>
<script src="../script/set_root.js"></script>

<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript" src="../script/hb.js"></script>
<script type="text/javascript" src="../script/vue.js"></script>
<!-- 环信接口 -->
<script type="text/javascript" src="../script/chat/easeChat.js"></script>
<script>
    apiready = function () {
        hb_ready()
        initVue();
    }

    function initVue() {
        // 使用vue做双向数据绑定
        var app = new Vue({
            el: "#app",
            data: {
                sendAuthCode: true,
                phoneNum: "",
                code: "",
                authTime: 60, //倒计时的秒数
                getAuthCode: '获取验证码',
                order: false
            },
            created: function () {
                api.addEventListener({
                    name: 'keyback'
                }, function (ret, err) {
                    api.closeWidget();
                });
            },
            methods: {
                getCode: function () {
                    if (!this.sendAuthCode) {
                        return;
                    }
                    if (!(/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/.test(this
                            .phoneNum))) {
                        toast('请填写正确的手机号后再获取验证码');
                        return;
                    }
                    var $this = this;

                    /* 原下发验证码,1125更换

                    get_ajax('base/sms/send/code', {
                        phone: this.phoneNum,
                    }, function (ret, err) {
                        // alert(JSON.stringify(ret));
                        if (ret.code != 200) {
                            $this.times();
                        } else {
                            toast("获取验证码失败")
                        }
                        toast("验证码发送成功");
                    });
                    */

                    // 20211125 Add - JacksonLoo 新下发验证码
                    let strMobile = this.phoneNum;
                    let strPlatform = api.systemType == "android" ? "android" : "ios";
                    let strIp = "127.0.0.1";

                    // 获取客户端IP地址
                    let modelIp = api.require("ipAddress");
                    modelIp.getIp({
                        isNetIp: true,
                        isIpV6: false
                    }, function (ret, err) {
                        if (ret.status) {
                            strIp = ret.ip;
                        }
                    });

                    get_ajax("doctors/login/verification", {
                        strMobile: strMobile,
                        strPlatform: strPlatform,
                        strIp: strIp
                    }, (ret, err) => {
                        if (ret.code == 0) {
                            toast(ret.content);
                            $this.times();
                        } else {
                            toast(ret.content);
                        }
                    });

                    // End
                },
                times: function () {
                    var $this = this;
                    this.sendAuthCode = false;
                    this.authTime = 60;
                    var authTimetimer = setInterval(function () {
                        $this.authTime--;
                        $this.getAuthCode = $this.authTime + "秒";
                        if ($this.authTime <= 0) {
                            $this.getAuthCode = "获取验证码"
                            $this.sendAuthCode = true;
                            clearInterval(authTimetimer);
                        }
                    }, 1000);
                },
                login: function () {
                    if (!this.phoneNum) {
                        toast("请输入手机号")
                        return
                    }
                    if (!this.code) {
                        toast("请输入验证码")
                        return
                    }
                    if (!this.order) {
                        toast("您需要仔细阅读并同意服务条款和隐私政策")
                        return
                    }

                    /* 原医生登录 1125更换

                    post_ajax("user/login", {
                        loginType: "sms",
                        credential: this.code,
                        principal: this.phoneNum,
                        clientType: "doctor"
                    }, function (res, err) {
                        // alert(JSON.stringify(res))
                        if (res.code == 2000) {
                            $api.setStorage("token", res.data)
                            get_ajax("doctor/parse/token", {
                                token: res.data
                            }, function (ret, errs) {
                                // alert(JSON.stringify(ret))
                                // alert(JSON.stringify(errs))
                                if (ret.code == 2000) {
                                    ret.data["phone"] = app.phoneNum
                                    $api.setStorage("emp", ret.data)
                                    // alert(JSON.stringify($api.getStorage("emp")))
                                    fnEaseChatLogin($api.getStorage("emp").userId,
                                        "YXA6FeeNhmMQTZm8faKN2JOJ4A"); // 环信登录
                                    api.openWin({
                                        name: 'main',
                                        url: 'main.html',
                                        pageParam: {
                                            login: 1
                                        }
                                    })
                                    api.sendEvent({
                                        name: 'login',
                                    });
                                } else {
                                    // toast(ret.msg)
                                    toast(ret.msg)
                                }
                            })
                        } else {
                            toast(res.msg)
                        }
                    })
                    */

                    // 20211125 Add - JacksonLoo 新医生登录
                    post_ajax("doctors/login", {
                        strMobile: this.phoneNum,
                        strVerifyCode: this.code
                    }, (ret, err) => {
                        if (ret.code == 0) {
                            toast(ret.content);
                            // 登录信息保存到内存中
                            let data = ret.data;
                            let strToken = data.token;
                            let userInfo = data.info;

                            $api.setStorage("token", strToken);
                            $api.setStorage("emp", userInfo);

                            // 等待添加环信登录

                            // 页面跳转
                            api.openWin({
                                name: "main",
                                url: "main.html",
                                pageParam: {
                                    login: 1
                                }
                            });
                            api.sendEvent({
                                name: "login"
                            });
                        } else {
                            toast(ret.content);
                        }
                    });

                    // End
                }
            } //endmethods
        })
    } //endfunc
</script>
